package model

type CommentRequest struct {
	ID     uint `json:"id"`                       // 主键
	Status uint `orm:"status"      json:"status"` // 状态
}

type CommentResponse struct {
	ID          uint   `json:"id"`                       // 主键
	ArticleID   uint   `json:"articleId"`                // 文章id
	ArticleName string `json:"articleName"`              // 文章名称
	Content     string `json:"content"`                  // 内容
	ParentID    uint   `json:"parentId"`                 // 父评论id
	UserID      uint   `json:"userId"`                   // 用户id
	Username    string `json:"username"`                 // 用户名
	CreateTime  string `json:"createTime"`               // 创建时间
	UpdateTime  string `json:"updateTime"`               // 更新时间
	DeleteTime  string `json:"deleteTime"`               // 删除时间
	Status      uint   `orm:"status"      json:"status"` // 状态
}

type CommentResponsePage struct {
	Page Page              `json:"page"`
	List []CommentResponse `json:"datalist"`
}

func (commentRequest CommentRequest) Convert() Comment {
	return Comment{
		Id:     commentRequest.ID,
		Status: commentRequest.Status,
	}
}

func (*CommentResponse) Convert(comment *Comment) *CommentResponse {
	return &CommentResponse{
		ID:         comment.Id,
		ArticleID:  comment.ArticleId,
		Content:    comment.Content,
		ParentID:   comment.ParentId,
		UserID:     comment.UserId,
		Username:   comment.Username,
		CreateTime: comment.CreateTime.String(),
		UpdateTime: comment.UpdateTime.String(),
		DeleteTime: comment.DeleteTime.String(),
		Status:     comment.Status,
	}
}

func (Comment) Convert(comment []Comment) []CommentResponse {
	var commentResponse = make([]CommentResponse, len(comment))
	for i := range comment {
		commentResponse[i] = *(commentResponse[i].Convert(&comment[i]))
	}
	return commentResponse
}
func (Comment) ConvertPage(comment []Comment, page Page) CommentResponsePage {
	var commentResponse = make([]CommentResponse, len(comment))
	for i := range comment {
		commentResponse[i] = *(commentResponse[i].Convert(&comment[i]))
	}
	return CommentResponsePage{
		Page: page,
		List: commentResponse,
	}
}
